<%-- 
    Document   : login
    Created on : 8-jun-2009, 22:08:48
    Author     : frankkie
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
  </head>
  <body>
    <%
    //System.out.println("login.jsp in ta house");
    //check of ie al is ingelogt
    if (session.getAttribute("ingelogd")!=null && session.getAttribute("ingelogd").equals("ja")){
      //IS AL INGELOGD
      response.sendRedirect("index.jsp");
    }
    //System.out.println("login.jsp in thha house");
   if (request.getParameter("gezien") != null) {
     //Controleren en zo
     eskuel.CMI_SQL sql = new eskuel.CMI_SQL(pak.Db.dbhost, pak.Db.dbname, pak.Db.dbpass);
     java.sql.ResultSet res = sql.selectieQuery("SELECT * FROM `cmi0806683`.`b_auth` WHERE `Gebruikersnaam` = '" + request.getParameter("naam") + "'");
     String MD5uitDB = "";
     try {
       while (res.next()) {
         MD5uitDB = res.getString("MD5_wachtwoord");
       }
     } catch (Exception ex) {
       System.out.println("login.jsp: Exception:\n" + ex);
     }

     // van de nu ingevulde code een MD5 maken
     com.twmacinta.util.MD5 md5 = new com.twmacinta.util.MD5();
     try {
       md5.Update(request.getParameter("w8w"), null);
     } catch (Exception e) {
       System.out.println("login.jsp: Het lukt niet om een MD5-code te maken...");
     }
     String hash = md5.asHex();
     //Vergelijken
     if (hash.equals(MD5uitDB)) {
       //REDIRECT !
       session.setAttribute("ingelogd", "ja");
       response.sendRedirect("index.jsp");
     }
   }
    %>
    <h1>Lucky Bank Beheer Login</h1>
    <form method="post" action="alogin.jsp">
      Naam<input type="text" name="naam" /><br />
      W8Woord<input type="password" name="w8w" /><br />
      <%
   out.println("<font color=\"red\">");
   if (request.getParameter("gezien") != null) {
     out.println("Naam en of W8woord onjuist");
   }
   out.println("</font><br />");
      %>
      <input type="hidden" name="gezien" value="ja" />
      <input type="submit" />
    </form>
  </body>
</html>
